package com.example.wxy.bbtapp.Common;

import java.util.List;

/**
 * Created by yons on 2017/9/11.
 */

public  class ListHelper<T> {

    public interface Expression<T>{
        boolean where(T org);
    }

    public  T FindFirst(List<T> list, Expression<T> where)
    {
        for (int i = 0; i < list.size(); i++) {
            if(where.where(list.get(i)))
            {
                return list.get(i);
            }
        }
        return null;
    }

    public int FindIndex(List<T> list, Expression<T> where)
    {
        for (int i = 0; i < list.size(); i++) {
            if(where.where(list.get(i)))
            {
                return i;
            }
        }
        return -1;
    }

    public  List<T> FindAll(List<T> list, Expression<T> where)
    {
        List<T> value =list.subList(0,0);

        for (int i = 0; i < list.size(); i++) {
            if(where.where(list.get(i)))
            {
                value.add(list.get(i));
            }
        }
        return value;
    }
}
